/**
 *  Copyright (c) 2017-2022 Rushang Co.Ltd All Rights Reserved.
 */
package com.rshang.rsdp.router;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;

import com.rshang.rsdp.annotation.Log;
import com.rshang.rsdp.common.status.StatusCode;
import com.rshang.rsdp.entity.TbUser;
import com.rshang.rsdp.exception.RsdpSystemException;
import com.rshang.rsdp.util.i18n.I18nMessage;

/**
 * 功能简介：系统路由基类<br/>
 * @author zhangjun
 * @create 2017年8月10日下午10:03:56
 * 
 */
public class BaseRouter {

	@Autowired
	I18nMessage i18n;
	
	@Autowired
	protected HttpServletRequest request;

	@Autowired
	protected HttpServletResponse response;
	
	/**
	 * 获取shiro对象
	 * @return	Subject
	 */
	protected Subject getSubject(){
		return SecurityUtils.getSubject();
	}
	
	/**
	 * 获取当前session登陆用户对象
	 * @return
	 * 		TbUser
	 */
	protected TbUser getSessionUser(){
		Subject currentUser = SecurityUtils.getSubject();
		if(currentUser.isAuthenticated()&&currentUser.getPrincipal()!=null){
			return (TbUser) currentUser.getPrincipal();
		}
		throw new RsdpSystemException(StatusCode.UNAUTHORIZED.getCode(),i18n.getMessage(StatusCode.UNAUTHORIZED.getKey()));
	}
}
